package Demo6;

/**
 * ClassName Test
 * Description TODO
 * Author Yanyan
 * Date 2025/11/11 22:02
 * Version 1.0
 */
public class Test {

    public static void main4(String[] args) {
        Animal animal = new Dog("大黄",10);
//向下转型
        if(animal instanceof Dog) {
            Dog dog = (Dog) animal;
            dog.bark();
            System.out.println("animal引用的是Dog对象");
        } else {
            System.out.println("animal引用的不是Dog对象");
        }

        if(animal instanceof Bird) {
            Bird bird = (Bird) animal;
            bird.fly();
            System.out.println("animal引用的是bird对象");
        } else {
            System.out.println("animal引用的不是bird对象");
        }
    }

    public static void func(Animal animal) {
        animal.eat();
    }

    public static Animal func2(int a) {
        if (a == 1) {
            return new Dog("xiaohei", 4);
        } else {
            return new Bird("小鸟",2);
        }
    }


    public static void main(String[] args) {
        Dog dog = new Dog("小狗",3);
        Bird bird = new Bird("鸟儿",4);
        func(dog);
        func(bird);
    }


    public static void main2(String[] args) {
/*        Dog dog = new Dog("大黄",10);
        Animal animal = dog;*/
        //向上转型

        Animal animal = new Dog("旺财",10);
        animal.eat();
        //优先用子类方法

    }


    //方法的重写
    public static void main1(String[] args) {
        Dog dog = new Dog("大黄",10);
        dog.eat();
    }
}
